﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
using LibNiconico.NiconicoApi.Extentions;

namespace LibNiconico.NiconicoApi.Lives.PublishStatus
{
    /// <summary>
    /// ニコニコ生放送パブリッシュステータス
    /// </summary>
    public sealed class NicoLivePublishStatus
    {
        internal NicoLivePublishStatus() 
        {
            Token = "";
            AllowVote = false;
        }

        /// <summary>
        /// トークン
        /// </summary>
        public string Token { get; internal set; }

        /// <summary>
        /// アンケート可能か取得?
        /// </summary>
        public bool AllowVote { get; internal set; }

        /// <summary>
        /// コメント解析
        /// </summary>
        /// <param name="element"></param>
        /// <returns></returns>
        internal static NicoLivePublishStatus Parse(XElement element)
        {
            var res = (from e in element.Elements("stream")
                       select new NicoLivePublishStatus
                       {
                           AllowVote = XElementExtention.GetElementAsBool(e,"allow_vote"),
                           Token = XElementExtention.GetElementAsString(e, "token")
                       });
            NicoLivePublishStatus status = new NicoLivePublishStatus();
            if (res.Count() > 0)
            {
                status = res.First();
            }

            return status;



        }

    }
}
